﻿using System;
using AutoMapper;
using CodeSaude.Application.ViewModels;
using CodeSaude.Domain.Entities;
using CodeSaude.Domain.Enums;

namespace CodeSaude.Application.AutoMapper
{
    public class MappingProfile : Profile
    {
        protected override void Configure()
        {

            //* REVERSEMAP *//
            Mapper.CreateMap<UsuarioViewModel, Usuario>().ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)))
                .ForMember(destination => destination.NomeGrupo,
                    opt => opt.MapFrom(source => source.GrupoUsuario.NomeGrupo));

            Mapper.CreateMap<GrupoUsuarioViewModel, GrupoUsuario>()
                .ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<AlergiaViewModel, Alergia>().ReverseMap().ForMember(destination => destination.Situacao,
                opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<AntecedenteViewModel, Antecedente>()
                .ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<LocalEspecialidadeViewModel, LocalEspecialidade>().ReverseMap();

            Mapper.CreateMap<DiagnosticoViewModel, Diagnostico>()
                .ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<DicionarioFoneticoViewModel, DicionarioFonetico>()
                .ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<CuidadoViewModel, Cuidado>().ReverseMap().ForMember(destination => destination.Situacao,
                opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<DietaViewModel, Dieta>().ReverseMap().ForMember(destination => destination.Situacao,
                opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<LocalAtendimentoViewModel, LocalAtendimento>().ReverseMap();

            Mapper.CreateMap<EspecialidadeViewModel, Especialidade>()
                .ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<ExameViewModel, Exame>().ReverseMap().ForMember(destination => destination.Situacao,
                opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<LeitoViewModel, Leito>().ReverseMap().ForMember(destination => destination.Situacao,
                opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<ProcedimentoViewModel, Procedimento>()
                .ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<ProntuarioViewModel, Prontuario>().ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)))
                .ForMember(destination => destination.Destino,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (DestinoEnum), source.IdDestino)))
                .ForMember(destination => destination.Prioridade,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (PrioridadeEnum), source.IdPrioridade)));

            Mapper.CreateMap<MenuViewModel, Menu>().ReverseMap().ForMember(destination => destination.Situacao,
                opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));
            Mapper.CreateMap<MenuViewModel, Menu>().ReverseMap();

            Mapper.CreateMap<PessoaViewModel, Pessoa>().ReverseMap().ForMember(destination => destination.Situacao,
                opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<OxigenoterapiaViewModel, Oxigenoterapia>()
                .ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

            Mapper.CreateMap<MedicamentoViewModel, Medicamento>()
                .ReverseMap()
                .ForMember(destination => destination.Situacao,
                    opt => opt.MapFrom(source => Enum.GetName(typeof (SituacaoEnum), source.IdSituacao)));

        }
    }
}
